package com.liangtian.mdm.base.dataSource;

import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

/**
 * Created by admin on 2018/6/4.
 */
public class MultipleDataSource extends AbstractRoutingDataSource {

    public static ThreadLocal<String> getDataSourceKey() {
        return dataSourceKey;
    }

    private static final ThreadLocal<String> dataSourceKey = new InheritableThreadLocal<String>();

    public static void setDataSourceKey(String dataSource) {
        dataSourceKey.remove();
        dataSourceKey.set(dataSource);
    }

    @Override
    protected Object determineCurrentLookupKey() {
        return dataSourceKey.get();
    }
}
